<template>
  <div>
    <!--  -->
    <h1>3、新增图书信息</h1>
    <input v-model="obj.bookname" type="text" placeholder="书名">
    <input v-model="obj.author" type="text" placeholder="作者">
    <input v-model="obj.publisher" type="text" placeholder="出版社">
    <button @click="addBook">点击新增图书</button>
  </div>
</template>

<script>
import axios from "axios"
export default {
  data(){
    return {
      obj: {
        appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
        bookname: "",
        author: "",
        publisher: ""
      }
    }
  },
  methods: {
    addBook(){
      // 实现新增
      axios({
        url: "http://123.57.109.30:3006/api/addbook",
        method: "post",
        // data: {
        //   appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
        //   bookname: this.obj.bookname,
        //   author: this.obj.author,
        //   publisher: this.obj.publisher
        // }
        data:{
          // ...扩展运算符
          ...this.obj
        }
      }).then(res=>{
        console.log("新增成功：",res);
      })
    }
  }
}
</script>

<style>

</style>